package com.jk.service.impl;

import com.jk.mapper.AuthUserIdcardMapper;
import com.jk.service.AuthUserIdcardService;
import com.jk.vo.AuthUserIdcard;
import com.jk.vo.Employee;
import com.jk.vo.WorkOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;


/**
 * Created by ${user} on ${data}.
 */
@Service("authUserIdcardService")
public class AuthUserIdcardServiceImpl implements AuthUserIdcardService {
    @Autowired
    private AuthUserIdcardMapper authUserIdcardMapper;

    public List<Map>  SelectAuthUserIdcard(AuthUserIdcard authUserIdcard ) {
        return authUserIdcardMapper.SelectAuthUserIdcard(authUserIdcard);
    }

    @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
    public int UpdateAuthUserIdcard(AuthUserIdcard authUserIdcard ,WorkOrder workOrder) {

      int  UpdateAuthUserIdCount =  authUserIdcardMapper.UpdateAuthUserIdcard(authUserIdcard);
      if (UpdateAuthUserIdCount!=0){
          if(authUserIdcard.getExamStatus()==2){
              workOrder.setWorkStatus(1);//认证通过
          }else{
              workOrder.setWorkStatus(2);//认证失败
          }
          workOrder.setWorkoderId(UUID.randomUUID().toString().replaceAll("-", ""));
          workOrder.setWorkoderNo(UUID.randomUUID().toString().replaceAll("-", ""));
          workOrder.setWorkoderDic(1);
          workOrder.setWorkoderTime(new Date());
          authUserIdcardMapper.InsertAuthUserIdcard(workOrder);
          return 1;//新增修改成功
      }else{
          return 0;//新增修改失败
      }

    }
}